#include "widget_funcc_smart_home.h"
#include "ui_widget_funcc_smart_home.h"

widget_funcc_smart_home::widget_funcc_smart_home(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::widget_funcc_smart_home),
    music_temp(false)
{
    ui->setupUi(this);
    
    ui->stay_button->setPixmap(QPixmap(":/new/prefix1/开关_开"));
    ui->leave_button->setPixmap(QPixmap(":/new/prefix1/开关_关"));
    ui->sleep_button->setPixmap(QPixmap(":/new/prefix1/开关_关"));
    ui->light_button->setPixmap(QPixmap(":/new/prefix1/开关_开"));
    ui->curtain_button->setPixmap(QPixmap(":/new/prefix1/开关_开"));
    ui->aircondition_button->setPixmap(QPixmap(":/new/prefix1/开关_开"));
    ui->sweeper_button->setPixmap(QPixmap(":/new/prefix1/开关_关"));
    ui->light_icon->setPixmap(QPixmap(":/new/prefix1/灯_开"));
    ui->curtain_icon->setPixmap(QPixmap(":/new/prefix1/窗帘_开"));
    ui->aircondition_icon->setPixmap(QPixmap(":/new/prefix1/空调_开"));
    ui->sweeper_icon_->setPixmap(QPixmap(":/new/prefix1/扫地机_关"));
    
    //连接按钮信号
    connect(ui->stay_button , &button_home::signals_start , this , &widget_funcc_smart_home::slots_button_start);
    connect(ui->leave_button , &button_home::signals_start , this , &widget_funcc_smart_home::slots_button_start);
    connect(ui->sleep_button , &button_home::signals_start , this , &widget_funcc_smart_home::slots_button_start);
    connect(ui->light_button , &button_home::signals_start , this , &widget_funcc_smart_home::slots_button_start);
    connect(ui->curtain_button , &button_home::signals_start , this , &widget_funcc_smart_home::slots_button_start);
    connect(ui->aircondition_button , &button_home::signals_start , this , &widget_funcc_smart_home::slots_button_start);
    connect(ui->sweeper_button , &button_home::signals_start , this , &widget_funcc_smart_home::slots_button_start);
    
}

widget_funcc_smart_home::~widget_funcc_smart_home()
{
    delete ui;
    delete dialog;
    delete Music_dialog;
}

void widget_funcc_smart_home::slots_button_start(bool start)
{
    QObject * temp = sender();
    //在家
    if(temp == ui->stay_button)
    {
        ui->stay_button->set_start(start);
        ui->sleep_button->set_start(!start);
        ui->leave_button->set_start(!start);
        ui->light_button->set_start(start);
        ui->light_icon->setPixmap(QPixmap(":/new/prefix1/灯_开"));
        ui->curtain_button->set_start(start);
        ui->curtain_icon->setPixmap(QPixmap(":/new/prefix1/窗帘_开"));
        ui->aircondition_button->set_start(start);
        ui->aircondition_icon->setPixmap(QPixmap(":/new/prefix1/空调_开"));
        ui->sweeper_button->set_start(!start);
        ui->sweeper_icon_->setPixmap(QPixmap(":/new/prefix1/扫地机_关"));
    }
    //离家
    if(temp == ui->leave_button)
    {
        ui->leave_button->set_start(start);
        ui->sleep_button->set_start(!start);
        ui->stay_button->set_start(!start);
        ui->light_button->set_start(!start);
        ui->light_icon->setPixmap(QPixmap(":/new/prefix1/灯_关"));
        ui->curtain_button->set_start(!start);
        ui->curtain_icon->setPixmap(QPixmap(":/new/prefix1/窗帘_关"));
        ui->aircondition_button->set_start(!start);
        ui->aircondition_icon->setPixmap(QPixmap(":/new/prefix1/空调_关"));
        ui->sweeper_button->set_start(start);
        ui->sweeper_icon_->setPixmap(QPixmap(":/new/prefix1/扫地机_开"));
    }
    //睡眠
    if(temp == ui->sleep_button)
    {
        ui->sleep_button->set_start(start);
        ui->leave_button->set_start(!start);
        ui->stay_button->set_start(!start);
        ui->light_button->set_start(!start);
        ui->light_icon->setPixmap(QPixmap(":/new/prefix1/灯_关"));
        ui->curtain_button->set_start(!start);
        ui->curtain_icon->setPixmap(QPixmap(":/new/prefix1/窗帘_关"));
        ui->aircondition_button->set_start(start);
        ui->aircondition_icon->setPixmap(QPixmap(":/new/prefix1/空调_开"));
        ui->sweeper_button->set_start(!start);
        ui->sweeper_icon_->setPixmap(QPixmap(":/new/prefix1/扫地机_关"));
    }
    if(temp == ui->light_button)
    {
        ui->light_button->set_start(start);
        ui->light_icon->setPixmap(QPixmap(":/new/prefix1/灯_关"));
        
    }
    if(temp == ui->curtain_button)
    {
        ui->curtain_button->set_start(start);
        ui->curtain_icon->setPixmap(QPixmap(":/new/prefix1/窗帘_关"));
        
    }
    if(temp == ui->aircondition_button)
    {
        ui->aircondition_button->set_start(start);
        ui->aircondition_icon->setPixmap(QPixmap(":/new/prefix1/空调_关"));
        
    }
    if(temp == ui->sweeper_button)
    {
        ui->sweeper_button->set_start(start);
        ui->sweeper_icon_->setPixmap(QPixmap(":/new/prefix1/扫地机_开"));
        
    }
}


void widget_funcc_smart_home::on_pushButton_clicked()
{
    dialog = new Aircondition_Dialog(this);
    dialog->setModal(false);
    dialog->show();
}

void widget_funcc_smart_home::on_music_button_clicked()
{
    Music_dialog = new music_dialog(this);
    Music_dialog->setModal(false);
    Music_dialog->show();
}


